package com.lzh.dlykserver.controller;

import com.github.pagehelper.PageInfo;
import com.lzh.dlykserver.entity.TActivityRemark;
import com.lzh.dlykserver.query.ActivityRemarkQuery;
import com.lzh.dlykserver.result.R;
import com.lzh.dlykserver.service.ActivityRemarkService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class ActivityRemarkController {

    @Resource
    private ActivityRemarkService aActivityRemarkService;

    /**
     * 提交活动备注
     * @param activityRemarkQuery
     * @param toklen
     * @return
     */
    @PostMapping("/api/activity/remark")
    public R addActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery,
                               @RequestHeader("Authorization") String toklen) {
        activityRemarkQuery.setToken(toklen);
        int save = aActivityRemarkService.saveaActivityRemark(activityRemarkQuery);
        return save >= 1 ? R.OK() : R.FAIL();
    }


    /**
     * 获取市场活动备注分页
     * @param current
     * @param activityId
     * @return
     */
    @GetMapping("/api/activity/remark")
    public R activityRemarkPage(@RequestParam(value = "current", required = false) Integer current,
                                @RequestParam("activityId") Integer activityId) {
        ActivityRemarkQuery activityRemarkQuery = new ActivityRemarkQuery();
        activityRemarkQuery.setActivityId(activityId);
        if (current == null) {
            current = 1;
        }
        PageInfo<TActivityRemark> pageInfo = aActivityRemarkService.getActivityRemarkByPage(current, activityRemarkQuery);
        return R.OK(pageInfo);
    }


    /**
     * 编辑市场活动备注
     * @param id
     * @return
     */
    @GetMapping("/api/activity/remark/{id}")
    public R editactivityRemark(@PathVariable("id") Integer id) {
        TActivityRemark tActivityRemark = aActivityRemarkService.getActivityRemarkById(id);
        return R.OK(tActivityRemark);
    }


    /**
     * 提交编辑市场活动备注
     * @param activityRemarkQuery
     * @param toklen
     * @return
     */
    @PutMapping("/api/activity/remark")
    public R editActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery,
                                @RequestHeader("Authorization") String toklen) {
        activityRemarkQuery.setToken(toklen);
        int update = aActivityRemarkService.updateaActivityRemark(activityRemarkQuery);
        return update >= 1 ? R.OK() : R.FAIL();
    }


    /**
     * 删除市场活动备注
     * @param id
     * @return
     */
    @DeleteMapping("/api/activity/remark/{id}")
    public R deleteActivityRemark(@PathVariable("id") Integer id) {
        int del = aActivityRemarkService.deleteActivityRemarkById(id);
        return del >= 1 ? R.OK() : R.FAIL();
    }

}
